package com.smart.controller;


import com.smart.entity.Result;
import com.smart.entity.TrainVideo;
import com.smart.service.ITrainVideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 在线培训视频 前端控制器
 * </p>
 *
 * @author Cookies
 * @since 2024-06-02
 */
@RestController
@CrossOrigin
@RequestMapping("/train-video")
@Api(tags = "培训视频相关接口")
public class TrainVideoController {
    @Autowired
    private ITrainVideoService trainVideoService;

    @GetMapping
    @ApiOperation(value = "获取培训视频列表", response = Result.class)
    public Result getTrainVideoList() {
        return Result.success(trainVideoService.list());
    }

    @PostMapping
    @ApiOperation(value = "添加培训视频", response = Result.class)
    public Result addTrainVideo(
            @RequestBody @ApiParam(name = "培训视频信息", required = true) TrainVideo trainVideo) {
        boolean isSucceed = trainVideoService.save(trainVideo);
        return isSucceed ? Result.success() : Result.error("系统繁忙，请稍后再试...");
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除指定培训视频", response = Result.class)
    public Result deleteTrainVideo(
            @PathVariable @ApiParam(name = "培训视频ID", required = true) Integer id) {
        boolean isSucceed = trainVideoService.removeById(id);
        return isSucceed ? Result.success() : Result.error("系统繁忙，请稍后再试...");
    }
}